﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Autenticacao
{
    public partial class frm_vachist : Form
    {
        System.Data.SqlClient.SqlConnection con;

        public Exploracao ex2;

        private string nomec;
        private string nomee;

        public frm_vachist(Exploracao ex1)
        {
            this.ex2 = ex1;
            InitializeComponent();

            this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            pesquisar_Vacinacao();
        }

        private void pesquisar_Vacinacao()
        {
            con = new System.Data.SqlClient.SqlConnection();
            con.ConnectionString = @"Data Source = ANDRÉ-PC\SQLEXPRESS; Initial Catalog = horsepw_bd; Integrated Security = True;";
            con.Open();

            int ide = ex2.get_id();
            SqlCommand command1 = con.CreateCommand();
            command1.CommandText = "SELECT data_administracao, (m.nome) as nome FROM Vacinacao_exploracao ve INNER JOIN Medicamentos m ON ve.id_medicamento = m.id_medicamento INNER JOIN Exploracao ex ON ve.id_exploracao = ex.id_exploracao WHERE ex.id_exploracao = " + ide + " and ex.oculto = 0";
            SqlDataReader readatrib = command1.ExecuteReader();

            this.dataGridView1.Rows.Clear();

            while (readatrib.Read())
            {
                int i = this.dataGridView1.Rows.Add();

                this.dataGridView1[0, i].Value = readatrib["data_administracao"].ToString();
                this.dataGridView1[1, i].Value = readatrib["nome"].ToString();
            }

            con.Close();

            con.Open();
            SqlCommand command2 = con.CreateCommand();
            command2.CommandText = "SELECT e.id_cliente, c.nome FROM Exploracao e INNER JOIN Cliente c ON e.id_cliente = c.id_cliente WHERE e.id_exploracao = " + ide + " and e.oculto = 0";
            SqlDataReader readatrib1 = command2.ExecuteReader();

            while (readatrib1.Read())
                nomec = readatrib1["nome"].ToString();
            txthv_nome.Text = nomec;
            con.Close();

            con.Open();
            SqlCommand command3 = con.CreateCommand();
            command3.CommandText = "SELECT tipo_exploracao FROM Exploracao WHERE id_exploracao = " + ide + " and oculto = 0";
            SqlDataReader readatrib2 = command3.ExecuteReader();

            while (readatrib2.Read())
                nomee = readatrib2["tipo_exploracao"].ToString();
            txthv_exp.Text = nomee;
            con.Close();
        }

        private void cmdhv_voltar_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
